<?php
//dicts Model
class DictsModel
{
	var $id;
	var $packagename;
	var $language;
	var $dicttype;
	var $kw;
	var $meaningandusage;
	var $synnonyms;
	var $karaoke;
	var $laoka;
	var $createddate;
	var $lastupdated;
	var $lastaccessed;
	var $hitcount;
	var $bywhom;
	var $isactivated;
	/*GET*/
	public function setId($id)
	{
		$this->id=$id;
		}
	public function setPackagename($packagename)
	{
		$this->packagename=$packagename;
		}
	public function setLanguage($language)
	{
		$this->language=$language;
		}
	public function setDictType($dicttype)
	{
		$this->dicttype=$dicttype;
		}	
	public function setKW($kw)
	{
		$this->kw=$kw;
		}
	public function setMeaningAndUsage($meaning)
	{
		$this->meaningandusage=$meaning;
		}	
	public function setSynonyms($synonyms)
	{
		$this->synnonyms=$synonyms;
		}
	public function setKaraoke($karaoke)
	{
		$this->karaoke=$karaoke;
		}
	public function setLaoka($laoka)
	{
		$this->laoka=$laoka;
		}
	public function setCreatedDate($createddate)
	{
		$this->createddate=$createddate;	
		}
	public function setLastUpdated($lasupdated)
	{
		$this->lastupdated=$lasupdated;
		}
	public function setLastAccessed($lastaccessed)
	{
		$this->lastaccessed=$lastaccessed;
		}
	public function setHitCount($hitcount)
	{
		$this->hitcount=$hitcount;
		}
	public function setByWhom($bywhom)
	{
		$this->bywhom=$bywhom;
		}
	public function setIsActivated($isactivated)
	{
		$this->isactivated=$isactivated;
		}
		/*GET*/
	public function getId()
	{
		return $this->id;
		}
	public function getPackagename()
	{
		return $this->packagename;
		}
	public function getLanguage()
	{
		return $this->language;
		}
	public function getDictType()
	{
		return $this->dicttype;
		}	
	public function getKW()
	{ 
		return $this->kw;
		}
	public function getMeaningAndUsage()
	{
return		$this->meaningandusage;
		}	
	public function getSynonyms()
	{
		return $this->synnonyms;
		}
	public function getKaraoke()
	{
		return $this->karaoke;
		}
	public function getLaoka()
	{
return		$this->laoka;
		}
	public function getCreatedDate()
	{
		return $this->createddate;
		}
	public function getLastUpdated()
	{
return		$this->lastupdated;
		}
	public function getLastAccessed()
	{
return		$this->lastaccessed;
		}
	public function getHitCount()
	{
		return $this->hitcount;
		}
	public function getByWhom()
	{
return		$this->bywhom;
		}
	public function getIsActivated()
	{
return		$this->isactivated;
		}
}
class DictsQuery
{
	private $dicts;
	public function DictsQuery()
	{
		$this->dicts=new DictsModel();
		}
		public function inserQuery()
		{
			$q="INSERT INTO `laodicts`.`dicts` (`packagename`, `Language`, `dicttype`, `kw`, `meaningandusage`, `synonyms`, `karaoke`, `laoka`, `createddate`, `lastupdated`, `lastaccessed`, `hitcount`, `bywhom`, `isactivated`) VALUES (%d, %s, %d, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, %s, %d);";
			$q=sprintf($q,
			mysql_escape_string($this->dicts->getPackagename()),
			mysql_escape_string($this->dicts->getLanguage()),
			mysql_escape_string($this->dicts->getDictType()),
			mysql_escape_string($this->dicts->getKW()),
			mysql_escape_string($this->dicts->getMeaningAndUsage()),
			mysql_escape_string($this->dicts->getSynonyms()),
			mysql_escape_string($this->dicts->getKaraoke()),
			mysql_escape_string($this->dicts->getLaoka()),
			mysql_escape_string($this->dicts->getCreatedDate()),
			mysql_escape_string($this->dicts->getLastUpdated()),
			mysql_escape_string($this->dicts->getLastAccessed()),
			mysql_escape_string($this->dicts->getHitCount()),
			mysql_escape_string($this->dicts->getIsActivated()));
			
			return mysql_query($q);
			}
		public function updateQuery()
		{
			$q="UPDATE `laodicts`.`dicts` SET `packagename` = %d,
			`Language` = %s,
			`dicttype` = %d,
			`kw` = %s,
			`meaningandusage` = %s,
			`synonyms` = %s,
			`karaoke` = %s,
			`laoka` = %s,
			`createddate` = %s,
			`lastupdated` = %s,
			`lastaccessed` = %s,
			`hitcount` = %d,
			`isactivated` = %d WHERE `dicts`.`id` =%d ";
			$q=sprintf($q,
			mysql_escape_string($this->dicts->getPackagename()),
			mysql_escape_string($this->dicts->getLanguage()),
			mysql_escape_string($this->dicts->getDictType()),
			mysql_escape_string($this->dicts->getKW()),
			mysql_escape_string($this->dicts->getMeaningAndUsage()),
			mysql_escape_string($this->dicts->getSynonyms()),
			mysql_escape_string($this->dicts->getKaraoke()),
			mysql_escape_string($this->dicts->getLaoka()),
			mysql_escape_string($this->dicts->getCreatedDate()),
			mysql_escape_string($this->dicts->getLastUpdated()),
			mysql_escape_string($this->dicts->getLastAccessed()),
			mysql_escape_string($this->dicts->getHitCount()),
			mysql_escape_string($this->dicts->getIsActivated()),
			mysql_escape_string($this->dicts->getId()));
			return mysql_query($q);
			
			}
		public function deleteQuery()
		{
			$q="delete dicts where id=%d";
			$q=sprintf($q,mysql_escape_string($this->dicts->getId()));
			return mysql_query($q);
			}
		public function selectQuery($kw="",$forcebegin=false,$packagename=-1,$dictid=-1)
		{
			if($packagename==-1) return "no records with package=-1";
			$arr=array();
			
	        if($kw!="")
			{
				if($forcebegin==true)
					$kw="%$kw";
				else
				$kw="%$kw%"; 	
			}
			else $kw="%%";
			$i=0;
			$query=sprintf("SELECT * FROM dicts where packagename = %d",mysql_escape_string($packagename));
			if($kw!="")
			{$query= sprintf("SELECT * FROM dicts where packagename = %d and kw like '%s' ",mysql_escape_string($packagename),mysql_escape_string($kw));
			//echo "$kw";
			}
			if($dictid>-1&&$packagename>-1)
			{
				$query= sprintf("SELECT * FROM dicts where packagename = %d and id = %d",mysql_escape_string($packagename),mysql_escape_string($dictid));
				//echo "here";
			}
			//die($query);
			$result=mysql_query($query);
			if($result==false)return $arr;
			$num=mysql_numrows($result);
			
			while ($i < $num) {
				$this->dicts=new DictsModel();
			
			$this->dicts->setId(mysql_result($result,$i,"id"));
			$this->dicts->setByWhom(mysql_result($result,$i,"bywhom"));
			$this->dicts->setCreatedDate(mysql_result($result,$i,"createddate"));
			$this->dicts->setDictType(mysql_result($result,$i,"dicttype"));
			$this->dicts->setHitCount(mysql_result($result,$i,"hitcount"));
			$this->dicts->setIsActivated(mysql_result($result,$i,"isactivated"));
			$this->dicts->setKaraoke(mysql_result($result,$i,"karaoke"));
			$this->dicts->setKW(mysql_result($result,$i,"kw"));
			$this->dicts->setLanguage(mysql_result($result,$i,"language"));
			$this->dicts->setLaoka(mysql_result($result,$i,"laoka"));
			$this->dicts->setLastAccessed(mysql_result($result,$i,"lastaccessed"));
			$this->dicts->setLastUpdated(mysql_result($result,$i,"lastupdated"));
			$this->dicts->setMeaningAndUsage(mysql_result($result,$i,"meaningandusage"));		
			$this->dicts->setPackagename(mysql_result($result,$i,"packagename"));	
			$this->dicts->setSynonyms(mysql_result($result,$i,"synonyms"));	
			
			$arr[]=$this->dicts;
			
			++$i;
			}
			//$b=new Dicts();
			//$b=(Dicts)$obj;
		
			return $arr;
		}
}
?>
